#region File Description
//-----------------------------------------------------------------------------
// PauseMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
#endregion

namespace GGJ
{
    /// <summary>
    /// The pause menu comes up over the top of the game,
    /// giving the player options to resume or quit.
    /// </summary>
    class EndGameMenuScreen : MenuScreen
    {
        #region Initialization


        private String scoreString;
        private String lostString;
        private GameplayScreen.Level previousType;

        /// <summary>
        /// Constructor.
        /// </summary>
        public EndGameMenuScreen(GameplayScreen.Level type,TimeSpan score, int lost)
            : base("GAME OVER")
        {
            // Create our menu entries.

            this.previousType = type;

            MenuEntry playAgainGameMenuEntry = new MenuEntry("Play again");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");

            scoreString = "You survived : "+score.TotalSeconds+" second(s)";
            lostString = "You lost " + lost + " loyal(s) fighter(s)";

            // Hook up menu event handlers.
            playAgainGameMenuEntry.Selected += PlayAgainMenuEntrySelected;
            quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(playAgainGameMenuEntry);
            MenuEntries.Add(quitGameMenuEntry);
        }


        #endregion

        #region Handle Input


        /// <summary>
        /// Event handler for when the Quit Game menu entry is selected.
        /// </summary>
        void QuitGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            const string message = "Are you sure you want to quit this game?";

            MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);

            confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;

            ScreenManager.AddScreen(confirmQuitMessageBox, ControllingPlayer);
        }
        void PlayAgainMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {

            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new BackgroundScreen(),
                                                          new GameplayScreen(previousType));
        }

        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to quit" message box. This uses the loading screen to
        /// transition from the game back to the main menu screen.
        /// </summary>
        void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                                           new MainMenuScreen());
        }


        #endregion

        public override int DrawContent(SpriteBatch spriteBatch)
        {
            Color titleColor = new Color(192, 255, 192) * TransitionAlpha;
            float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
            SpriteFont font = ScreenManager.Font;



            Vector2 position = new Vector2(800 / 2, 150);     
            Vector2 scoreOrigin = font.MeasureString(scoreString) / 2;
            Vector2 position2 = new Vector2(800 / 2, 200);
            Vector2 scoreOrigin2 = font.MeasureString(lostString) / 2;
          
            float titleScale = 1.25f;

            position.Y -= transitionOffset * 100;
            position2.Y -= transitionOffset * 100;

            spriteBatch.DrawString(font, scoreString, position, titleColor, 0,
                                   scoreOrigin, titleScale, SpriteEffects.None, 0);

            spriteBatch.DrawString(font, lostString, position2, titleColor, 0,
                                   scoreOrigin, titleScale, SpriteEffects.None, 0);

            return 100;
        }



    }
}
